<?php

/**
 * 收费管理
 * File Name：MoneyController.php
 * File Encoding：UTF-8
 * File New Time：2014-5-14 9:20:19
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class MoneyController extends AdminBase {

    //订单查询
    public function actionOrders() {
        //搜索
        if (IS_POST) {
            $this->redirect(AdminBase::U('orders', $_POST));
            exit;
        }
        $where = array(
            'order' => 'add_time desc',
            //'payment_types'=> 7,
            'payment_types'=> array('IN',array(7,9))
        );
        //状态
        $status = $_GET['status'];
        if ($status != '') {
            $where['status'] = array('EQ', (int) $status);
            $this->assign('status', $status);
        }
        //搜索类型
        $type = (int) $_GET['type'];
        $keyword = trim($_GET['keyword']);
        if ($keyword) {
            $this->assign('type', $type);
            $this->assign('keyword', $keyword);
            if ($type == 1) {
                $where['product_id'] = array('EQ', $keyword);
            } else if ($type == 2) {
                $where['order_sn'] = array('EQ', $keyword);
            } else if ($type == 3) {
                $where['alipay_sn'] = array('EQ', $keyword);
            }
        }

        //分页
        $pageId = isset($_GET['page']) ? (int) $_GET['page'] : 1;
        //分页数
        $limit = 20;
        //订单模型
        $model = MoneyPositionOrderModel::model();
        $criteria = $model->where($where);
        //信息总数
        $count = $model->count($criteria);
        //分页
        $page = AdminBase::page($count, $limit, $pageId);
        //查询信息
        $criteria->limit = $page->listRows;
        $criteria->offset = $page->firstRow;
        $data = $model->findAll($criteria);

        $this->assign("Page", $page->show());
        $this->assign('data', $data);
        $this->assign('count', $count);
        $this->assign('where', $where);
        $this->render();
    }

    //确认上活动
    public function actionActivity() {
        $id = Yii::app()->request->getParam('id');
        $model = MoneyPositionOrderModel::model();
        $data = $model->findByPk($id);
        if (empty($data)) {
            $this->error('该订单信息不存在！');
        }
        $data->status = 2;
        if ($data->save(false)) {
            $this->success('确认上活动成功！');
        } else {
            $this->error('操作失败！');
        }
    }

    //类型
    public function actionType() {
        $model = MoneyPositionModel::model();
        $data = $model->findAll($model->where(array('order' => 'id desc')));

        $this->assign('data', $data);
        $this->render();
    }

    //添加收费类型
    public function actionAddtype() {
        $this->baseAdd('MoneyPositionModel', 'type');
    }

    //编辑收费类型
    public function actionEdittype() {
        $this->baseEdit('MoneyPositionModel', 'type');
    }

    //删除收费类型
    public function actionDeltype() {
        $this->baseDelete('MoneyPositionModel', 'type');
    }

}
